<?php
namespace app\index\controller;
header("Content-type:text/html;charset=utf-8");

use app\admin\validate\UserRule;
use app\common\controller\Frontend;
use app\common\model\Category;
use think\view\driver\Think;
use app\common\model\App;

class Game extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';


    //app列表
    public function index()
    {

        $Category=new Category();
        $category=$Category->getCategoryArray();
        $this->assign('category',$category);

        $mod=model('App');
        $cate=$mod->getCateNameList();
        $this->assign('cate',$cate);
        $params=$this->request->param();

        //过滤字符,防止sql注入
        $cate_name=strip_tags($params['name']);

        if(empty($params['type'])){

            $list=db('app')
                ->where(['cate_name'=>$cate_name])
                ->paginate(30);
        }else{
            //过滤字符,防止sql注入
            $type_name=strip_tags($params['type']);
            $query_params=[
                "type"=>$type_name,
            ];
            $list=db('app')
                ->where(['type_name'=>$type_name])
                ->paginate(30,false,['query'=>$query_params]);

        }
        $page = $list->render();
        $type=db('app_type')->where('cate_name',$cate_name)->select();

        switch ($params['name']){
            case 'BT':
                $params['name']='bt';
                break;
            case '单机':
                $params['name']='dj';
                break;
            case '应用':
                $params['name']='yy';
                break;
            case '网游':
                $params['name']='wy';
                break;
        }
        $this->assign('params',$params);
        $this->assign("name",$params['name']);
        $this->assign('list',$list);
        $this->assign('type',$type);
        $this->assign('page',$page);
        $this->assign("total",$list->total());
        return $this->fetch();
    }


    //app详情
    public function view()
    {
        $Category=new Category();
        $category=$Category->getCategoryArray();
        $this->assign('category',$category);

        $mod=model('App');
        $cate=$mod->getCateNameList();
        $this->assign('cate',$cate);

        //获取ID,强转为int

        $id=request()->param("id");
        $id=intval($id);

        $view=db('app')->where("id",$id)->find();

        $str=$view['content'];
        $gzip_content=base64_decode($str);
        $json_content=gzuncompress($gzip_content);
        $str_content=json_decode($json_content,true);
        $view['content']=$str_content;

        $bb_name=mb_substr($view['app_name'],0,3);
        $qtbb=db('app')->where('app_name','like','%'.$bb_name.'%')->limit(10)->select();
        $blzx=db('app')->where(['type_name'=>$view['type_name']])->limit(8)->select();
        $rmyx=db('app')->order("id","desc")->limit(0,6)->select();
        $tj_app=db('app')->limit($id,30)->select();


        $this->assign('view',$view);
        $this->assign('qtbb',$qtbb);
        $this->assign('blzx',$blzx);
        $this->assign('rmyx',$rmyx);

        $this->assign('tj_app',$tj_app);
        return $this->fetch();
    }



}

